# coding = utf-8
# Author = Ann
# Date: 2023/6/27

import configparser
import os.path


# config Profile reader
class ConfigReader:
    # Read the config file according to [module].
    def __init__(self):
        self.config_absolute_path = None
        self.config_manager = None

    def read(self, module):
        """
        Read the ini configuration file
        :param module: Module parameters for the configuration file
        :return: Returns the value of a specific parameter
        """
        # Configuration file path
        current_dir = os.getcwd()
        # parent_dir = os.path.dirname(current_dir)
        self.config_absolute_path = os.path.abspath(os.path.join(current_dir, os.pardir)) + r'/resources/pytest.ini'
        print(self.config_absolute_path)
        # Create a profile manager
        self.config_manager = configparser.ConfigParser()
        # Read the configuration file in UTF-8 encoding
        self.config_manager.read(self.config_absolute_path, encoding="utf-8")
        # Returns the read profile content dictionary
        return dict(self.config_manager.items(module))

    # Returns the absolute path to the configuration file
    def get_config_absolute_path(self):
        """
        Returns an absolute path
        """
        return self.config_absolute_path
